/** +----------------------------------------------------------------------
 *
 * +----------------------------------------------------------------------
 * | Copyright (c) 2020~2023 https://www.dswjcms.com All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed 未经许可不能去掉DSSHOP相关版权
 * +----------------------------------------------------------------------
 * | Author: Purl <383354826@qq.com>
 * +----------------------------------------------------------------------
 */
import Vue from 'vue'
// 千分位
// export function thousands(val) {
//   return parseFloat(val)
//     .toFixed(0)
//     .replace(/(\d)(?=(\d{3})+\.)/g, '$1,')
// }
export function thousands(value) {
  if (!value) return 0
  // 获取整数部分
  const intPart = Math.trunc(value)
  // 整数部分处理，增加,
  const intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
  // 预定义小数部分
  let floatPart = ''
  // 将数值截取为小数部分和整数部分
  const valueArray = value.toString().split('.')
  if (valueArray.length === 2) {
    // 有小数部分
    floatPart = valueArray[1].toString() // 取得小数部分
    return intPartFormat + '.' + floatPart
  }
  return intPartFormat + floatPart
}
// 显示小图片
export function smallImage(img, size) {
  // var index = img.lastIndexOf('.')
  // if (!size) size = 300
  return img
}
let filters = {
  thousands,
  smallImage
}

Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
export default filters
